package com.ruoyi.doorcontrol.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.doorcontrol.Acs.FaceControl;
import com.ruoyi.doorcontrol.domain.ThDoorControl;
import com.ruoyi.doorcontrol.service.HkFaceService;
import org.json.JSONException;
import org.springframework.stereotype.Service;



@Service
public class HkFaceServiceImpl implements HkFaceService {
    @Override
    public AjaxResult searchFaceInfo(ThDoorControl control, String employeeNo) {
        AjaxResult ajaxResult = null;
        Integer integer = ThDoorControlServiceImpl.loginHandleMap.get(control.getIpadress());
        if(integer == null){
            throw new CustomException(control.getNotes()+"未登录！");
        }
        try {
            ajaxResult = FaceControl.searchFaceInfo(integer, employeeNo);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Override
    public AjaxResult addFaceByBinary(ThDoorControl control,String employeeNo, String imgUrl) {
        Integer integer = ThDoorControlServiceImpl.loginHandleMap.get(control.getIpadress());
        if(integer == null){
            throw new CustomException(control.getNotes()+"未登录！");
        }
        AjaxResult ajaxResult = null;
        try {
            System.out.println("HKFaceServiceImpl---Integer="+integer+"----employeeNo="+employeeNo+"--imgUrl="+imgUrl);
            ajaxResult = FaceControl.addFaceByBinary(integer, employeeNo,imgUrl);
        } catch (JSONException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Override
    public AjaxResult addFaceByUrl(ThDoorControl control,String employeeNo,String url) {
        Integer integer = ThDoorControlServiceImpl.loginHandleMap.get(control.getIpadress());
        if(integer == null){
            throw new CustomException(control.getNotes()+"未登录！");
        }
        AjaxResult ajaxResult = null;
        try {
            ajaxResult = FaceControl.addFaceByUrl(integer, employeeNo,url);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ajaxResult;
    }

    @Override
    public AjaxResult deleteFaceInfo(ThDoorControl control,String employeeNo) {
        Integer integer = ThDoorControlServiceImpl.loginHandleMap.get(control.getIpadress());
        if(integer == null){
            throw new CustomException(control.getNotes()+"未登录！");
        }
        AjaxResult ajaxResult = FaceControl.deleteFaceInfo(integer, employeeNo);
        return ajaxResult;
    }

    @Override
    public AjaxResult captureFaceInfo(ThDoorControl control) {
        Integer integer = ThDoorControlServiceImpl.loginHandleMap.get(control.getIpadress());
        if(integer == null){
            throw new CustomException(control.getNotes()+"未登录！");
        }
        AjaxResult ajaxResult = FaceControl.captureFaceInfo(integer);
        return ajaxResult;
    }
}
